package com.fds.app.comm.threadpool;

import java.util.List;
import java.util.concurrent.Future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import com.fds.app.comm.batch.ProcessIndividualTr;
import com.fds.app.comm.domain.NvProcCondDto;

@Component
public class NvBatchExecutor {
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private ApplicationContext context;
	
	@Autowired
	private ThreadPoolTaskExecutor taskExecutor;


	public void start(List<NvProcCondDto> nvProcCondDtoLs) {

		try {
			
			for(NvProcCondDto nvProcCondDto : nvProcCondDtoLs) {
				// Prototype Dependency Lookup			
				ProcessIndividualTr processIndividualTr = context.getBean(ProcessIndividualTr.class);
				
				processIndividualTr.setNvProcCondDto(nvProcCondDto);
				
				Future<String> result = taskExecutor.submit(processIndividualTr);
				
				logger.info("result : {}", result.get());
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
